import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;

import 'action.dart';
import 'state.dart';

Widget buildView(
    HomeworkAnswerState state, Dispatch dispatch, ViewService viewService) {
  Color fontColor() {
    switch (state.statuscn) {
      case '未提交':
        return Colors.blue;
        break;
      case '待批阅':
        return Colors.orange;
        break;
      default:
        return Colors.grey;
    }
  }

  return Card(
      color: Colors.white,
      elevation: 5.0,
      margin: new EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
      child: FlatButton(
        onPressed: () => dispatch(HomeworkAnswerActionCreator.onClick()),
        child: Column(
          children: <Widget>[
            SizedBox(height: 16),
            Row(
              children: <Widget>[
                SizedBox(width: 8),
                Text(state.name,
                    style:
                        TextStyle(fontWeight: FontWeight.w500, fontSize: 18)),
                Spacer(),
                Text(state.statuscn, style: TextStyle(color: fontColor())),
                SizedBox(width: 8),
              ],
            ),
            SizedBox(height: 8),
            Divider(height: 1),
            SizedBox(height: 16),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Column(
                  children: <Widget>[
                    Text(
                      state.machineScore,
                      style: TextStyle(color: Colors.blue, fontSize: 20),
                    ),
                    Text(
                      'AI智能评分',
                      style: TextStyle(color: Colors.grey),
                    )
                  ],
                ),
                SizedBox(width: 8),
                Column(
                  children: <Widget>[
                    Text(
                      state.teacherScore,
                      style: TextStyle(color: Colors.blue, fontSize: 20),
                    ),
                    Text(
                      '老师评分',
                      style: TextStyle(color: Colors.grey),
                    )
                  ],
                ),
                SizedBox(width: 8),
                Column(
                  children: <Widget>[
                    Text(
                      state.practiceCount.toString(),
                      style: TextStyle(color: Colors.grey, fontSize: 20),
                    ),
                    Text(
                      '修改次数',
                      style: TextStyle(color: Colors.grey),
                    )
                  ],
                ),
              ],
            ),
            SizedBox(height: 20),
          ],
        ),
      ));
}
